package com.nuanshui.heatedloan.web.appsystem;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.nuanshui.heatedloan.baseservice.facade.ClientVersionService;
import com.nuanshui.heatedloan.baseservice.model.ClientVersion;
import com.nuanshui.heatedloan.constant.GlobalParam;
import com.nuanshui.heatedloan.pageable.Pager;
import com.nuanshui.heatedloan.web.ApiController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/cms/manage/clientversion")
public class ManageClientVersionController extends ApiController{

	@Reference(url = GlobalParam.BASESERVICE_DUBBO_SERVER, timeout = GlobalParam.DUBBO_SERVER_TIME_OUT,version = GlobalParam.BASESERVICE_DUBBO_SERVER_VERSION)
	private ClientVersionService clientVersionService;
	
	@RequestMapping("/list")
	public String list(Pager<ClientVersion> pager ,String query){

		ClientVersion cv = null;
		if(StringUtils.isNotEmpty(query) && !DEFAULTQUERYSTR.equals(query)){
			cv = JSON.parseObject(query, ClientVersion.class);
			if(StringUtils.isNotEmpty(cv.getName())){
				cv.setName("%" + cv.getName() + "%");
			}
		}
		pager = clientVersionService.list(pager,cv);
		List<ClientVersion> data = pager.getData();
		return success(pager.asHashMap());
	}
	
	@RequestMapping("/create")
	public String create(ClientVersion cv){
		clientVersionService.save(cv);
		return success();
	}
	
	@RequestMapping("/delete")
	public String delete(String id){
		clientVersionService.delete(id);
		return success();
	}
	
	@RequestMapping("/update")
	public String update(ClientVersion cv){
		clientVersionService.update(cv);
		return success();
	}
}
